package com.lxm.enigma.core;

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Lys
 * @Date 2022/5/31
 * @Describe
 **/
@Endpoint(id = "cipher-monitor")
public class CipherMonitor {

    private final EnigmaConfig enigmaConfig;

    public CipherMonitor(EnigmaConfig enigmaConfig) {
        this.enigmaConfig = enigmaConfig;
    }

    /**
     * 监控中心。
     *
     * @return
     */
    @ReadOperation
    public Map<String, Object> cipherMonitorDetail() {
        var data = new HashMap<String, Object>();
        var signList = enigmaConfig.getSignArray();
        data.put("sign-type|enc&dec", Map.of("size", signList.size(), "list", signList));
        var encStreamList = enigmaConfig.getEncStreamArray();
        data.put("stream-type|enc", Map.of("size", encStreamList.size(), "list", encStreamList));
        var encDataList = enigmaConfig.getEncDataArray();
        data.put("data-type|enc", Map.of("size", encDataList.size(), "list", encDataList));
        var decList = enigmaConfig.getDecArray();
        data.put("all-type|dec", Map.of("size", decList.size(), "list", decList));
        String charset = enigmaConfig.getResponseCharset();
        boolean debug = enigmaConfig.isDebug();
        String signTag = enigmaConfig.getSignTag();
        data.put("config",Map.of("charset",charset,"is-debug",debug,"sign-tag",signTag));
        return data;
    }
}
